<?php

namespace app\zyhsapi\controller\v2;

use app\zyhsapi\controller\ZyhsAuth;
use app\zyhsapi\model\ZyhsConsultChatRtcRecord;
use app\zyhsapi\model\ZyhsUserQuestion;

class Service extends ZyhsAuth
{
    private $appType1 = 1; // 1=>准有好事 2=>准了APP

    public function getList()
    {
        $type = input('type/d', 0);
        if (!in_array($type, [1, 2], true))
        {
            return show(config('code.error'), '请求异常，请稍后再试～');
        }

        if ($type === 1)
        {
            $resData = (new ZyhsConsultChatRtcRecord())->getRtcServiceList($this->appType1, $this->user['id']);
        } else
        {
            $zyhsUserQuestionModel = new ZyhsUserQuestion();
            $resData = $zyhsUserQuestionModel->getListPage($this->user['id'], 'create_time', ['id', 'question', 'order_num', 'question_type', 'receiving_num']);
            $resData['data'] = $zyhsUserQuestionModel->dataInit($resData['data']);
            $res = [];
            $questionTypeArr = [
                1 => '星盘',
                2 => '骰子',
                3 => '幸运卡牌',
            ];
            foreach ($resData['data'] as $dataItem)
            {
                $questionType = $questionTypeArr[$dataItem['question_type']] . "-{$dataItem['receiving_num']}人回复";
                $res[] = [
                    'id' => (int)($dataItem['id'] ?? 0),
                    'avatar' => '',
                    'name' => $dataItem['question'],
                    'list' => [
                        [
                            'name' => '服务编号',
                            'value' => $dataItem['order_num'] ?? 0,
                        ],
                        [
                            'name' => '问题类型',
                            'value' => $questionType,
                        ],
                    ],
                ];
            }
            $resData['data'] = $res;
        }

        return show(config('code.success'), '请求成功', $resData);
    }
}
